package com.miaomiao.utils;

import cn.hutool.extra.mail.MailUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;

import java.util.*;

@Component
public class SendEmailNotice {

    @Autowired
    TemplateEngine templateEngine;

    public void sendNotice(List<String> emails, String notice){
        // 设置渲染到html页面对应的值
        Context context = new Context();
        context.setVariable("SYSTEM_NOTICE",notice);
        context.setVariable("SYSTEM_NAME","小挑招募回复");
        context.setVariable("SYSTEM_WEIXIN","lxq3035155298");
        //利用模板引擎加载html文件进行渲染并生成对应的字符串
        String emailContent = templateEngine.process("emailTemplate_notice1", context);
        emails.forEach(item -> {
            MailUtil.send(item,"小挑招募回复",emailContent,true);
        });
    }
}
